#include "edge.h"

#include <stdio.h>
#include <stdlib.h>

Edge * newEdge(){
	Edge * e = (Edge *)malloc(sizeof(Edge));
	e->a = newPoint();
	e->b = newPoint();
	return e;
}

void freeEdge(Edge * e){
	free(e);
}

int compareEdge(Edge * e1, Edge * e2){
	int equals = 0;
	if(compare(e1->a, e2->a) == 0)
		equals++;
	if(compare(e1->a, e2->b) == 0)
		equals++;
	if(compare(e1->b, e2->a) == 0)
		equals++;
	if(compare(e1->b, e2->b) == 0)
		equals++;
	if(equals == 2)
		return 1;
	return 0;
}

void printEdge(Edge * e){
	printf("Edge=[%g,%g--%g,%g]\n", e->a->x, e->a->y, e->b->x, e->b->y);
}

//e1 - prosta, e2 - odcinek
int isIntersect(Edge * e1, Edge * e2){
	//if((halfPlane(e2->a, e1->a, e1->b) * halfPlane(e2->b, e1->a, e1->b) <= 0) && (halfPlane(e1->a, e2->a, e2->b) * halfPlane(e1->b, e2->a, e2->b) <= 0))
	if(halfPlane(e2->a, e1->a, e1->b) * halfPlane(e2->b, e1->a, e1->b) <= 0)
		return 1;
	return 0;
}
